import {
  BufferGeometry,
  Geometry,
  Material,
  Mesh,
  Object3D,
} from 'three-legacy';

export class MyMesh<
  TGeometry extends Geometry | BufferGeometry = Geometry | BufferGeometry,
  TMaterial extends Material | Material[] = Material | Material[],
> extends Mesh<TGeometry, TMaterial> {
  modelDxid: string;

  constructor(geometry: TGeometry, material: TMaterial, modelDxid: string) {
    super(geometry, material);
    this.modelDxid = modelDxid;
  }

  addTo(parent: Object3D) {
    this.parent?.remove(this);

    this.parent = parent;
    this.parent?.add(this);
  }

  destroy() {
    this.parent?.remove(this);

    this.geometry?.dispose();
  }
}
